package ch07_GUI编程;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;

public class JMenuDemo {
	public static void main(String[] args) {
		BaseFrame f = new BaseFrame("JMenu Demo");
		JMenuBar bar = new JMenuBar();

		JMenu menuFile = new JMenu("文件（F）");
		menuFile.setMnemonic(KeyEvent.VK_F);

		JMenuItem mil = new JMenuItem("新建");
		JMenuItem mi2 = new JMenuItem("打开(o)",KeyEvent.VK_O);
		JMenuItem mi3 = new JMenuItem("保存",ImageFactory.create("save.png"));
		mi3.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S,ActionEvent.ALT_MASK));

		menuFile.add(mil);
		menuFile.add(mi2);
		menuFile.addSeparator();
		menuFile.add(mi3);

		JMenu saveAsMenu = new JMenu("另存为");
		JMenuItem mi4 = new JMenuItem("文本文件");
		mi4.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_T,ActionEvent.CTRL_MASK));
		JMenuItem mi5 =new JMenuItem("图片文件");
		saveAsMenu.add(mi4);
		saveAsMenu.add(mi5);

		menuFile.add(saveAsMenu);
		menuFile.addSeparator();

		JRadioButtonMenuItem mi6 = new JRadioButtonMenuItem("宋体");
		JRadioButtonMenuItem mi7 = new JRadioButtonMenuItem("楷体");
		JRadioButtonMenuItem mi8 = new JRadioButtonMenuItem("隶书");
		ButtonGroup bg = new ButtonGroup();
		bg.add(mi6);
		bg.add(mi7);
		bg.add(mi8);
		menuFile.add(mi6);
		menuFile.add(mi7);
		menuFile.add(mi8);
		menuFile.addSeparator();

		JCheckBoxMenuItem mi9 = new JCheckBoxMenuItem("粗体",true);
		JCheckBoxMenuItem mi10 = new JCheckBoxMenuItem("斜体");
		menuFile.add(mi9);
		menuFile.add(mi10);

		bar.add(menuFile);
		bar.add(new JMenu("编辑"));

		f.setJMenuBar(bar);
		f.showMe();
	}
}
